package com.magnificent.atlantis.server.settings;

import com.magnificent.commons.utils.settings.JAXBUtils;

import java.io.File;

/**
 * User: Babanin
 * Date: 03.04.2009
 * Time: 23:51:09
 */
public class SettingsStorage {  
      private static String SETTINGS_PATH = "dataServer/settings.xml";

    private static Settings settings;

    private static Class[] classes = new Class[]{
            Settings.class 
    };

    public static Settings getSettings() {
        if (settings == null) {
            if (new File(SETTINGS_PATH).exists()) {
                settings = (Settings) JAXBUtils.loadSettings(SETTINGS_PATH, classes);
            } else {
                settings = initializeSettings();
            }
        }

        return settings;
    }

    public static void saveSettings() {
        if (settings == null) {
            settings = initializeSettings();
        }

        JAXBUtils.saveSettings(SETTINGS_PATH, classes, settings);
    }

    private static Settings initializeSettings() {
        return new Settings();
    }
}
